<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;

class UserController extends LoginController {
	public function __construct() {
		parent::__construct ();
		// S(array('type'=>'File','prefix'=>'cate','expire'=>60));
		layout ( false );
	}
	
	/**
	 * 用户管理
	 * 
	 * @access public
	 * @param char $_POST
	 *        	用户提交信息
	 * @param int $id
	 *        	用户id
	 */
	public function user() {
		if (! empty ( $_POST )) {
			
			//表单令牌环检查
			$this->checkToken($_POST);
			$this->db = D ( "User" );
			$arr = $_POST;
			$arr ['password'] = md5 ( $arr ['password'] );
			if (! $_POST ['id']) {
				$arr ['creatdate'] = date ( "Y-m-d H:i:s" );
				$this->db->add ( $arr );
			} else {
				if ($this->user_group == 10) {
					$this->db->where ( array (
							'id' => $arr ['id'] 
					) )->save ( $arr );
				}
			}
		}
		// 读取用户信息
		$this->db = D ( 'User' );
		$userinfo = $this->db->getInfo ();
		$this->assign ( array (
				"userinfo" => $userinfo 
		) );
		
		$this->display ( "user" );
	}
	public function checkUserid() {
		$user_id = $_POST ['user_id'];
		$this->db = D ( 'User' );
		$userinfo = $this->db->getInfo ( array (
				'user_id' => $user_id 
		) );
		echo count ( $userinfo );
		exit ();
	}
	
	/**
	 * 获取用户信息
	 * 
	 * @access public
	 * @param char $id
	 *        	用户ID
	 */
	public function getUser() {
		$id = $_POST ['id'];
		$this->db = D ( 'User' );
		$data = $this->db->select ( $id );
		$this->ajaxReturn ( $data [0] );
	}
	
	/**
	 * 删除用户
	 * 
	 * @access public
	 * @param int $id
	 *        	用户ID
	 */
	public function deUser() {
		$id = $_POST ['id'];
		$this->db = D ( 'User' );
		$this->db->where ( array (
				'id' => $id 
		) )->delete ();
		echo true;
	}
}
?>